package controller.link.game;

import view.client.Console;
import model.Hearer;
import view.client.PanelGame;
import java.io.Serializable;
import controller.Link;
import model.game.Place;
import model.game.Scenario;
import model.User;
import java.util.ArrayList;
import model.game.Item;
import model.Attendant;
import model.Server;
import model.game.Location;

public class Ask4Local implements Link, Serializable {

    private String nameLocal;
    private ArrayList<Item> items;

    public Ask4Local() {
    }

    public Ask4Local(Hearer h) {
        h.send((Link) this);
    }

    @Override
    public void serverUse(Server server, Attendant at) {
        User user = at.getUser();
        Location local = server.getWorld().getMap().whereIsPlayer(user.getPlayer().getName());
        items = local.getItems();
        nameLocal = local.getName();
        at.send((Link)this);
    }

    public String getNameLocal() {
        return nameLocal;
    }

    @Override
    public void clientUse(Console console) {
        PanelGame pg = console.getPg();
        pg.getModelObject().removeAllElements();
        for (int i=0; i<items.size(); i++){
            pg.getModelObject().add(i, items.get(i).getName());
        }
        pg.getLblLocal().setText("Local: " + nameLocal);
        pg.revalidate();
        console.getFrame().repaint();
    }
}
